package com.bite.system.service.manager;

import com.bite.common.core.constants.CacheConstants;
import com.bite.common.redis.service.RedisService;
import com.bite.system.domain.exam.Exam;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

@Service
public class ExamCacheService {

    @Autowired
    private RedisService redisService;

    // 添加缓存
    public void addCache(Exam exam) {
        redisService.leftPushForList(getExamListKey(), exam.getExamId());
        redisService.setCacheObject(getDetailKey(exam.getExamId()), exam);
    }

    // 删除缓存
    public void deleteCache(long examId) {
        redisService.removeForList(getExamListKey(), examId);
        redisService.deleteObject(getDetailKey(examId));
    }

    // 获取考试列表的缓存键
    private String getExamListKey() {
        return CacheConstants.EXAM_UNFINISHED_LIST;
    }

    // 获取考试详细信息的缓存键
    private String getDetailKey(long examId) {
        return CacheConstants.EXAM_DETAIL + examId;
    }
}